1
|
|
|
import { |
2
|
|
|
Entity, |
3
|
|
|
Column, |
4
|
|
|
PrimaryGeneratedColumn, |
5
|
|
|
Index, |
6
|
|
|
OneToOne, |
7
|
|
|
JoinColumn |
8
|
|
|
} from 'typeorm'; |
9
|
|
|
import {UserAdministrative} from './UserAdministrative.entity'; |
10
|
|
|
|
11
|
|
|
export enum UserRole { |
12
|
|
|
COOPERATOR = 'cooperator', |
13
|
|
|
EMPLOYEE = 'employee', |
14
|
|
|
ACCOUNTANT = 'accountant' |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
@Entity() |
18
|
|
|
export class User { |
19
|
|
|
@PrimaryGeneratedColumn('uuid') |
20
|
|
|
private id: string; |
21
|
|
|
|
22
|
|
|
@Column({type: 'varchar', nullable: false}) |
23
|
|
|
private firstName: string; |
24
|
|
|
|
25
|
|
|
@Column({type: 'varchar', nullable: false}) |
26
|
|
|
private lastName: string; |
27
|
|
|
|
28
|
|
|
@Column({type: 'varchar', unique: true, nullable: false}) |
29
|
|
|
private email: string; |
30
|
|
|
|
31
|
|
|
@Index('api-token') |
32
|
|
|
@Column({type: 'varchar', nullable: true}) |
33
|
|
|
private apiToken: string; |
34
|
|
|
|
35
|
|
|
@Column({type: 'varchar', nullable: false}) |
36
|
|
|
private password: string; |
37
|
|
|
|
38
|
|
|
@Column('enum', {enum: UserRole, nullable: false}) |
39
|
|
|
private role: UserRole; |
40
|
|
|
|
41
|
|
|
@OneToOne(type => UserAdministrative, {nullable: true}) |
42
|
|
|
@JoinColumn() |
43
|
|
|
private userAdministrative: UserAdministrative; |
44
|
|
|
|
45
|
|
|
@Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'}) |
46
|
|
|
private createdAt: Date; |
47
|
|
|
|
48
|
|
|
constructor( |
49
|
|
|
firstName: string, |
50
|
|
|
lastName: string, |
51
|
|
|
email: string, |
52
|
|
|
apiToken: string, |
53
|
|
|
password: string, |
54
|
|
|
role: UserRole, |
55
|
|
|
userAdministrative?: UserAdministrative |
56
|
|
|
) { |
57
|
|
|
this.firstName = firstName; |
58
|
|
|
this.lastName = lastName; |
59
|
|
|
this.email = email; |
60
|
|
|
this.apiToken = apiToken; |
61
|
|
|
this.password = password; |
62
|
|
|
this.role = role; |
63
|
|
|
this.userAdministrative = userAdministrative; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public getId(): string { |
67
|
|
|
return this.id; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public getFirstName(): string { |
71
|
|
|
return this.firstName; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public getLastName(): string { |
75
|
|
|
return this.lastName; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public getEmail(): string { |
79
|
|
|
return this.email; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public getApiToken(): string { |
83
|
|
|
return this.apiToken; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public getPassword(): string { |
87
|
|
|
return this.password; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public getRole(): UserRole { |
91
|
|
|
return this.role; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public getFullName(): string { |
95
|
|
|
return `${this.firstName} ${this.lastName}`; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public getUserAdministrative(): UserAdministrative { |
99
|
|
|
return this.userAdministrative; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public update(firstName: string, lastName: string, email: string): void { |
103
|
|
|
this.firstName = firstName; |
104
|
|
|
this.lastName = lastName; |
105
|
|
|
this.email = email; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public updatePassword(password: string): void { |
109
|
|
|
this.password = password; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|